<!doctype html>
<html style="height: 0px !important">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>  
</head>
<style>
	input::-webkit-input-placeholder { /* WebKit, Blink, Edge */
	    color:    #fff;
	}
	input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
	   color:    #fff;
	}
	input::-moz-placeholder { /* Mozilla Firefox 19+ */
	   color:    #fff;
	}
	input:-ms-input-placeholder { /* Internet Explorer 10-11 */
	   color:    #fff;
</style>
<body class="dl-bg-100">
	<div class="dl-logo cd_dl-logo">
		<img src="../../image/logo.png">
	</div>
	<div class="dl-kuang">
		<form id="form">
			<!-- 输入手机号 -->
			<img src="../../image/dl-yh.png" class="aui-pull-left di-img-posi">
			<input type="number" class="dl-text" placeholder="请输入手机号" id="account" name="account">
			<div class="bai-1"></div>
			<!-- 输入密码 -->
			<img src="../../image/dl-ma.png" class="aui-pull-left di-img-posi">
			<input type="password" class="dl-pw" placeholder="请输入登录密码" id="password" name="password">
			<div class="bai-1"></div>
			<!-- 发送验证码 -->
			<img src="../../image/zhuce-xf.png" class="aui-pull-left di-img-posi1">
			<div class="aui-pull-left bai-ban-1">
				<input type="text" class="dl-pw dl-yzm aui-pull-left" placeholder="验证码" id="verify" name="verify">
			</div>
			<a class="zc-hqyzm aui-pull-right" onclick="sendSMS(this,event);">获取验证码</a>
			<!-- 注册 -->
			<input class="aui-btn aui-btn-bai aui-btn-outlined aui-btn-fff dl-button" type="button" value="注册" onclick="doRegister();">
			<span class="aui-pull-left dl-span" onclick="api.closeWin();">立即登录</span>
		</form>	
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script>
var db_key = 'user',db_user ,ajpushID='';
var JPushID_interval;
var myfrom,myParam = {};
apiready = function() {
    myfrom = $api.byId('form');
}

function syncJPushID() {
    ajpushID = $api.getStorage('ajpushID');
    try {
        if (ajpushID != '' && typeof(ajpushID)!='undefined') {
            window.clearInterval(JPushID_interval);
            _doRegister();
        }
    }catch(e){}
    return true;
}
//注册验证
function doRegister() {
    var preg = new RegExp(/1\d{10}/);
    if(!preg.test(myfrom.account.value)) {
        api.toast({msg: '请输入正确的手机号码！'});
        return false;
    }
    if (myfrom.password.value=='') {
        api.toast({msg: '密码不能为空'});
        return false;
    }
//  if (myfrom.yzm.value=='') {
//      api.toast({msg: '验证码不能为空'});
//      return false;
//  }    
    
    api.showProgress();//显示加载进度框
    
    //JPushID_interval = setInterval("syncJPushID()", 500);
    ajpushID = $api.getStorage('ajpushID');
    _doRegister();
}

function _doRegister() {
    myParam.rtk = RSapi.myrtk;
    myParam.account = myfrom.account.value;
    myParam.newpwd = myfrom.password.value;
    myParam.verify = myfrom.verify.value;
    myParam.jpushid = ajpushID;
    //alert(myParam.jpushid);
//      myParam.logsinfo = api.systemType+' '+api.systemVersion+' '+api.deviceModel;//用于记录登录日志
    
    api.ajax({
        url: RSapi.base+RSapi.Mregister,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: myParam },
    }, function(ret, err){
        api.hideProgress();//隐藏加载进度框
        if(err){
            //alert(JSON.stringify(err));
            api.alert({msg: JSON.stringify(err)});
        }else {
            if (ret.status == 1) {
                api.alert({msg: '注册成功，请登录！'},function(ret,err){
                    api.closeWin();
                });
            }else {
                //失败了
                api.toast({msg: ret.info});
            }
        }
    });
    return false;
}
/*发送验证码*/
function sendSMS(obj,e) {
	e.preventDefault();
		var preg = new RegExp(/1\d{10}/);
		if(preg.test(myfrom.account.value)) {
			//倒计时开始
			$api.attr(obj,'disabled','disabled');
			var wait = 60;
			obj.innerHTML = "重新发送（"+wait+"）";
			var interval = setInterval(function(){
				wait = --wait;
				if(wait <= 0) {
					obj.innerHTML = "发送验证码";
					$api.removeAttr(obj,'disabled');
					clearInterval(interval);
				}else {
					obj.innerHTML = "重新发送（"+wait+"）";
				}
			}, 1000);
			// 发送验证码
			api.ajax({
				url: RSapi.base+RSapi.Mverify,
				method: 'post',
				cache: false,
				timeout: 30,
				dataType: 'json',
				data: { values: {rtk:RSapi.myrtk, phone:myfrom.account.value, actstr: '注册用户', check:2} },//确保用户不存在
			}, function(ret, err){
				if(err){//请求失败
					wait=1;
					//alert(JSON.stringify(err));
					api.alert({msg: JSON.stringify(err)});
				}else {
					if (ret.status) {
						//成功了
						verify_code = ret.info.code;
						verify_phone = ret.info.phone;
						api.toast({msg:'短信验已发送成功，请注意查收！'});
					}else {
						//失败了
						wait=1;
						api.toast({msg: ret.info});
					}
				}
			});
		}else {
			api.toast({msg: "请输入正确的手机号码"});
		}
}
</script>
</html>